package com.itheima4;

import java.util.ArrayList;

public class ArraylistTest {
    public static void main(String[] args) {
//创建集合对象
        ArrayList<students> array = new ArrayList<students>();

//创建学生对象
        students s1 = new students("李素裳", "18");
        students s2 = new students("hanser", "30");
        students s3 = new students("嘉然", "666");
        students s4 = new students("史蒂夫", "45");
        students s5 = new students("冰糖雪梨", "24");

//添加学生对象到集合中
        array.add(s1);
        array.add(s2);
        array.add(s3);
        array.add(s4);
        array.add(s5);
//遍历集合，采用通用格式
        for (int i = 0; i < array.size(); i++) {
            students s = array.get(i);
            System.out.println(s.getName() + "," + s.getYears());

        }


    }
}
